import java.util.ArrayList;
import java.util.List;

public class KthSmalles {

    List<Integer> list = new ArrayList<>();
    public int kthSmallest(TreeNode root, int k) {
        midOrder(root);
        return list.get(k - 1);
    }

    public void midOrder(TreeNode node) {
        if (node == null) return;
        midOrder(node.left);
        list.add(node.val);
        midOrder(node.right);
    }
}
